<template>
  <div>
    <div class="top-leader">
      <el-menu
        :default-active="activeIndex"
        class="el-menu-demo"
        mode="horizontal"
        @select="handleSelect"
      >
        <!-- <el-submenu index="1">
          <template #title>整体分析</template>
          <el-menu-item index="1-1" @click="gorecovery">回收概况</el-menu-item>
          <el-menu-item index="1-2" @click="goanalysis">数据统计</el-menu-item>
        </el-submenu> -->
        <el-menu-item index="1" @click="gorecovery">整体分析</el-menu-item>
        <el-menu-item index="2" @click="godetail">详细分析</el-menu-item>
        <el-menu-item index="3" @click="gocross">交叉分析</el-menu-item>
        <el-menu-item index="4" @click="exportdata">导出原数据</el-menu-item>
        <el-menu-item index="5" @click="exportdata_sta">导出统计数据</el-menu-item>
        <!-- <a @click="exportdata" :href="url">导出原数据</a> -->
      </el-menu>
      <div class="line"></div>
    </div>
    <div>
      <detailedanalysis
        v-show="detail"
        :id="questionnaire_ids"
      ></detailedanalysis>
      <recoveryanalysis
        v-show="recovery"
        :id="questionnaire_ids"
      ></recoveryanalysis>
      <crossanalysis v-show="cross" :options="options" :questionnaire_id="this.questionnaire_ids"></crossanalysis>
      <allananlysis v-show="analysis"></allananlysis>
      <export-page v-show="exporter || exporter_sta"></export-page>
      <judge-page v-show="vote" :id="questionnaire_ids"></judge-page>
    </div>
  </div>
</template>

<script>
import Detailedanalysis from "@/components/Analysis/AnalysisPages/Detailedanalysis";
import Recoveryanalysis from "@/components/Analysis/AnalysisPages/Recoveryanalysis";
import Allananlysis from "@/components/Analysis/AnalysisPages/Allananlysis";
import ExportPage from "@/components/Analysis/AnalysisPages/ExportPage";
import Crossanalysis from '@/components/Analysis/AnalysisPages/Crossanalysis';
// import VoteAnalysis from '@/components/Analysis/AnalysisPages/VoteAnalysis'
import axios from "axios";
export default {
  props: {
    questionnaire_ids: Number,
  },
  data() {
    return {
      url: "",
      id: "111",
      detail: false,
      recovery: true,
      analysis: false,
      exporter: false,
      exporter_sta:false,
      cross:false,
      options:null,
      vote:false
    };
  },
  created(){

  },

  components: {
    Detailedanalysis,
    Recoveryanalysis,
    Allananlysis,
    ExportPage,
    Crossanalysis,
  },
  methods: {
    //点击触发页面跳转
    godetail() {
      if (this.$data.detail === false) {
        (this.$data.detail = true),
          (this.$data.recovery = false),
          (this.$data.analysis = false),
          (this.$data.exporter = false);
          this.exporter_sta=false;
          this.cross=false;
      }
    },
    gorecovery() {
      if (this.$data.recovery === false) {
        (this.$data.detail = false),
          (this.$data.recovery = true),
          (this.$data.analysis = false),
          (this.$data.exporter = false);
          this.exporter_sta=false;
          this.cross=false;
      }
    },
    goanalysis() {
      if (this.$data.analysis === false) {
        (this.$data.detail = false),
          (this.$data.recovery = false),
          (this.$data.analysis = true),
          (this.$data.exporter = false);
          this.exporter_sta=false;
          this.cross=false;
      }
    },
    exportdata() {
      if (this.$data.exporter === false) {
        (this.$data.detail = false),
          (this.$data.recovery = false),
          (this.$data.analysis = false),
          (this.$data.exporter = true);
          this.exporter_sta=false;
          this.cross=false;
      }
      axios
        .post("export_raw_data/", { qid: this.questionnaire_ids })
        .then((res) => {
          if (res.data.code === 0) {
            console.log(res);
            this.url = res.data.path;
            console.log(this.url)
            alert("导出成功！");
            
            // window.location.href = this.url;
            window.open(this.url);
          }
          if (res.data.code === 404) {
            // console.log(res);
            // this.url = res.data.path;
            // console.log(this.url)
            alert("无有效数据，暂无法导出！");
            
            // window.location.href = this.url;
            // window.open(this.url);
          }
        });
    },
    exportdata_sta() {
      if (this.$data.exporter_sta === false) {
        (this.$data.detail = false),
          (this.$data.recovery = false),
          (this.$data.analysis = false),
          (this.$data.exporter = false);
          this.exporter_sta=true;
          this.cross=false;
      }
      
      axios
        .post("export_statistical_data/", { qid: this.questionnaire_ids })
        .then((res) => {
          if (res.data.code === 0) {
            console.log(res);
            this.url = res.data.path;
            console.log(this.url)
            alert("导出成功！");
            
            // window.location.href = this.url;
            window.open(this.url);
          }
          if (res.data.code === 404) {
            // console.log(res);
            // this.url = res.data.path;
            // console.log(this.url)
            alert("有效统计数据为空，暂无法导出！");
            
            // window.location.href = this.url;
            // window.open(this.url);
          }
        });
    },
    gocross(){
      if (this.$data.cross === false) {
        (this.$data.detail = false),
          (this.$data.recovery = false),
          (this.$data.analysis = false),
          (this.$data.exporter = false);
          this.exporter_sta=false;
          this.cross=true;
      }
      axios
        .post("cross_statistic_get_info/", { qid: this.questionnaire_ids })
        .then((res) => {
          if (res.data.code === 0) {
            console.log(res);
            this.options=res.data.question_info
            console.log(this.options);
            console.log(res.data.question_info)
          }
        });
    },
  },
};
</script>
